<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>ShellExecutor</title>
</head>

<body>

	<script language="javascript" type="text/javascript">
		var request = false;
		try {
			request = new XMLHttpRequest();
		} catch (trymicrosoft) {
			try {
				request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (othermicrosoft) {
				try {
					request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed) {
					request = false;
				}
			}
		}
		if (!request)
			alert("Error initializing XMLHttpRequest!");
		function getCustomerInfo(path) {

			var url = "<%=request.getContextPath()%>/ShellExecutorServlet?path="
					+ path;
			request.open("GET", url, true);
			request.onreadystatechange = updatePage;
			request.send(null);
		}
		function updatePage() {
			if (request.readyState == 4) {
				var r = request.responseText;
				if (r != "") {
					var msgdiv = document.getElementById("msg");
					msgdiv.innerHTML = r;
				}
			}

		}

		function onSubmitCongestion(path) {
			var pathbutton = document.getElementById("path");
			pathbutton.value = path;
			//document.getElementById("form").submit();
			var msgdiv = document.getElementById("msg");
			msgdiv.innerHTML = "<img src='img/waiting.gif'/>Network Congestion, Sending notification to UPM...";
			getCustomerInfo(path);

		}

		function onSubmitNormal(path) {
			var pathbutton = document.getElementById("path");
			pathbutton.value = path;
			//document.getElementById("form").submit();
			var msgdiv = document.getElementById("msg");
			msgdiv.innerHTML = "<img src='img/waiting.gif'/>Network Normal, Sending notification to UPM...";
			getCustomerInfo(path);
		}
	</script>

	<p>Shell Script Executor</p>
	<form action="ShellExecutorServlet" method="post" id="form">
		<input type="hidden" name="path" id="path"> <input
			type="button" onclick="onSubmitCongestion(this.title)"
			value="Network Congestion" title="/root/notifyCongestion.sh">
		<input type="button" onclick="onSubmitNormal(this.title)"
			value="Network Normal" title="/root/notifyNormal.sh">
			<input type="button" onclick="onSubmitNormal(this.title)"
			value="Network Normal" title="c:/test.bat">
	</form>

	<div id="msg" style="color: black"></div>

</body>
</html>